package com.wave.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.wave.common.annotation.Log;
import com.wave.common.annotation.RepeatSubmit;
import com.wave.common.core.controller.BaseController;
import com.wave.common.core.domain.PageQuery;
import com.wave.common.core.domain.R;
import com.wave.common.core.page.TableDataInfo;
import com.wave.common.core.validate.AddGroup;
import com.wave.common.core.validate.EditGroup;
import com.wave.common.enums.BusinessType;
import com.wave.common.utils.poi.ExcelUtil;
import com.wave.system.domain.bo.SysMechanicalArmInfoBo;
import com.wave.system.domain.vo.SysMechanicalArmInfoVo;
import com.wave.system.service.ISysMechanicalArmInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 机械臂信息
 *
 * @author wave
 * @date 2024-10-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/mechanicalArmInfo")
public class SysMechanicalArmInfoController extends BaseController {

    private final ISysMechanicalArmInfoService iSysMechanicalArmInfoService;

    /**
     * 查询机械臂信息列表
     */
    @SaCheckPermission("system:mechanicalArmInfo:list")
    @GetMapping("/list")
    public TableDataInfo<SysMechanicalArmInfoVo> list(SysMechanicalArmInfoBo bo, PageQuery pageQuery) {
        return iSysMechanicalArmInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出机械臂信息列表
     */
    @SaCheckPermission("system:mechanicalArmInfo:export")
    @Log(title = "机械臂信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysMechanicalArmInfoBo bo, HttpServletResponse response) {
        List<SysMechanicalArmInfoVo> list = iSysMechanicalArmInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "机械臂信息", SysMechanicalArmInfoVo.class, response);
    }

    /**
     * 获取机械臂信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:mechanicalArmInfo:query")
    @GetMapping("/{id}")
    public R<SysMechanicalArmInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iSysMechanicalArmInfoService.queryById(id));
    }

    /**
     * 新增机械臂信息
     */
    @SaCheckPermission("system:mechanicalArmInfo:add")
    @Log(title = "机械臂信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysMechanicalArmInfoBo bo) {
        return toAjax(iSysMechanicalArmInfoService.insertByBo(bo));
    }

    /**
     * 修改机械臂信息
     */
    @SaCheckPermission("system:mechanicalArmInfo:edit")
    @Log(title = "机械臂信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysMechanicalArmInfoBo bo) {
        return toAjax(iSysMechanicalArmInfoService.updateByBo(bo));
    }

    /**
     * 删除机械臂信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:mechanicalArmInfo:remove")
    @Log(title = "机械臂信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iSysMechanicalArmInfoService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
